package com.ning.weixin.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ning.weixin.dto.IndexDto;
import com.ning.weixin.entity.UserInfo;
import com.ning.weixin.service.UserInfoService;
import com.ning.weixin.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 领取奖品
 * @author Cyan
 * @Date:2018/12/10
 */
@Api(description = "领取奖品")
@RestController
@RequestMapping("/njxs/receive")
public class ReceiveController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("领取奖品")
    @RequestMapping(value = "/prize", method = RequestMethod.POST)
    public R prize(@RequestBody IndexDto indexDto) {
        String openId = indexDto.getOpenId();
        String userName = indexDto.getUserName();
        String userTel = indexDto.getUserTel();
        if (userName != null && userTel != null && openId != null) {
            userInfoService.updateNameAndTel(new UserInfo(openId, userName, userTel));
            return R.ok("恭喜,领取奖品成功");
        }else if (userName == null){
            return R.error("您的用户名未填写，请重新填写");
        }else if (userTel == null){
            return R.error("您的手机号码未填写，请重新填写");
        }else {
            return R.error("您已掉线，请重连");
        }
    }

}
